package com.kusiri.kframework.salesforce.model
{
	import com.kusiri.kframework.model.IKfDataModel;
	
	/**
	 * Model for salesforce
	 */
	public interface IKfSalesforceModel extends IKfDataModel
	{
		/**
		 * Gets a KF description for a type of sobject
		 */
		function getKfDescriptionForType( type : String ) : XML;
		
		/**
		 * Get the deafult(?) lauout for an object type
		 * TODO: Recordtypes
		 */
		function describeLayout(sobjectType:String, onSuccess:Function, onFail:Function) : void;

		/**
		 * Gets the salesforce user id of the current user
		 */
		function get __currentUserId() : String;

		/**
		 * Get an sobject from the cache
		 */
		function getFromCache(id : String) : ISObject;
		
		/**
		 * Set an sobject in the cache
		 */
		function setInCache(id : String, sobject : ISObject) : void;

		/**
		 * TODO: is this used?
		 */
		function relationshipNameToFieldName(relationshipName:String) : String;
		
		/**
		 * Escape a string for querying
		 */
		function escape(string:String) : String;
		
		/**
		 * Get SOQL (minus the WHERE clause) to select an object
		 */
		function getSoqlToSelect(sobjectType : String) :String;
		
		/**
		 * Get all the DescribeISObjectResults
		 */
		function get __descriptions() : Object;
		
		/**
		 * Get the map of object name => field names
		 */
		function get __fieldNames() : Object;
		
		/**
		 * Search for sobjects
		 */
		function findSObjects(keywords:String, sobjectType:String, onSuccess:Function, onFail:Function) : void;
		
		/**
		 * Get an Sobject
		 */
		function getSObject(sobjectType:String, Id:String, onSuccess:Function, onFail:Function, forceReload:Boolean = false) : void;	 	
	 	/**
	 	 * Special function to get activity history, as it's not a standard object
	 	 */
	 	function getActivityHistory(sobject:ISObject, onSuccess:Function, onFail:Function) : void;
	 	
	 	/**
	 	 * Get a selection of sobjects of a single type
	 	 */
	 	function getSObjects(sobjectType:String, queryCondition:String, onSuccess:Function, onFail:Function) : void;
	
		
		/**
		 * All objects in salesforce
		 */
		function getAllObjectNames(onSuccess: Function, onFail: Function) : void;

		/**
		 * 
		 */
		function objectNameToLabel(name:String) : String;
		
		/**
		 * 
		 */
		function objectNamesToLabels(names:Array) : Array;
		
		
		/**
		 * onSuccess takes the salesforce id of the object
		 */
		function deleteObject(sobject:ISObject, onSuccess:Function = null, onFail:Function = null) : void;	

		/**
		 * onSuccess takes the salesforce ids Array of the objects
		 */
		function deleteObjects(valueObjects:Array, onSuccess:Function = null, onFail:Function = null) : void;

		/**
		 * This will update the kusiri model copy
		 * 
		 * TODO: change this to take a simple value object + type, not a sf sobject
		 * 
		 * onSuccess takes the kusiri sobject
		 */
	 	function saveObject(sobjectType:String, pofo:Object, onSuccess:Function = null, onFail:Function = null) : void;
	}
}